/**
*   FuzzyEngine - an Simple flex framework 
*   Copyright (C) 2010 Constantin Aldea
*
*   This program is free software: you can redistribute it and/or modify
*   it under the terms of the GNU General Public License as published by
*   the Free Software Foundation, either version 3 of the License, or
*   (at your option) any later version.
*   This program is distributed in the hope that it will be useful,
*   but WITHOUT ANY WARRANTY; without even the implied warranty of
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*   GNU General Public License for more details.
*
*   You should have received a copy of the GNU General Public License
*   along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
package fuzzy.penelope.helpers {
	import mx.collections.ArrayCollection;
	public class ArraysUtility
	{
        
        public static function getIndexAtNeedle(collection:ArrayCollection, field:String, needle:*):int{      	
        	for each(var item:Object in collection){
        		if(item && item[field] == needle){
        			return collection.getItemIndex(item);
        		}
        	}
        	return -1;
        }
        
        public static function inArray( needle:*, haystack:Array ):Boolean{   
         			var itemIndex:int = haystack.indexOf( needle );   
         			return ( itemIndex < 0 ) ? false : true;
    	}
    
    	public static function inCollection(needle:String, collection:ArrayCollection, field:String):Boolean{
			for each(var item:Object in collection){
					if(item[field] == needle) {
						 return true;
					}	 
   			}		
   			return false;
		}
	
		public static function searchArray (theArray:Array, searchElement:Object):Boolean {
          for (var i:int = 0; i < theArray.length; i++) {
            if (theArray[i] == searchElement) {
              return true;
            }
          }
          return false;
        }
	}
}